package com.yunxi.controller.approve;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.freeze.pojo.AmountFreezeVO;
import com.yunxi.freeze.service.AmountFreezeDubboService;
import com.yunxi.order.pojo.PartnerFreezeAmountReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2019-07-09
 */
@RestController
@RequestMapping("/admin/amountFreeze")
@Api(tags = "pms:amountFreeze", description = "资金冻结接口")
public class AmountFreezeController {
 private static final Logger logger = LoggerFactory.getLogger(AmountFreezeController.class);

 @Autowired
 AmountFreezeDubboService amountFreezeDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 public ApiResult page(AmountFreezeVO amountFreezeVO, Integer pageNum, Integer pageSize) throws Exception {
     return ResponseUtil.ok(amountFreezeDubboService.findPageByVO(amountFreezeVO,pageNum,pageSize));
 }

   @GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult list(AmountFreezeVO amountFreezeVO) throws Exception {
      return ResponseUtil.ok(amountFreezeDubboService.listByVo(amountFreezeVO));
   }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 public ApiResult load(AmountFreezeVO amountFreezeVO, @CurrentUser LoginInfo loginInfo) throws Exception {
 return ResponseUtil.ok(amountFreezeDubboService.getById(amountFreezeVO.getFreezeId()));
}

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody AmountFreezeVO amountFreezeVO,@CurrentUser LoginInfo loginInfo) throws Exception {
     amountFreezeVO.setCreateBy(loginInfo.getUserCode());
     amountFreezeDubboService.saveOrUpdate(amountFreezeVO);
     return ResponseUtil.ok("success");
}

 @PostMapping("/del")
 @ApiOperation(value = "删除")
 public ApiResult del(@RequestBody List<AmountFreezeVO> amountFreezeVOList) throws Exception {
    amountFreezeDubboService.removeByListVo(amountFreezeVOList);
    return ResponseUtil.ok("success");
 }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(amountFreezeDubboService.findMapByList(params));
}*/



    @GetMapping("/searchFreezeAmountOem")
    @ApiOperation(value = "厂端查询渠道商资金冻结列表")
    public ApiResult amountFreezeSearch(PartnerFreezeAmountReqVO reqVO,Integer pageNum, Integer pageSize,@CurrentUser LoginInfo user) throws Exception {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }
        return ResponseUtil.ok(amountFreezeDubboService.listPartnerFreezeAmount(reqVO,pageNum,pageSize));
    }


    @GetMapping("/searchFreezeAmountDealer")
    @ApiOperation(value = "店端查询渠道商资金冻结列表")
    public ApiResult amountFreezeSearchDealer(PartnerFreezeAmountReqVO reqVO,Integer pageNum, Integer pageSize,@CurrentUser LoginInfo user) throws Exception {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO == null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是渠道用户，请使用渠道用户登录！");
        }
        reqVO.setPartnerCode(user.getPartnerCode());
        return ResponseUtil.ok(amountFreezeDubboService.listPartnerFreezeAmount(reqVO,pageNum,pageSize));
    }


    @GetMapping("/searchFreezeAmountDetailOem")
    @ApiOperation(value = "厂端查询渠道商资金冻结变动明细")
    public ApiResult amountFreezeChangeDetailOem(PartnerFreezeAmountReqVO reqVO,Integer pageNum, Integer pageSize,@CurrentUser LoginInfo user) throws Exception {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }
        if(reqVO.getPartnerCode() == null){//如果未传经销商代码,则返回错误
            return ResponseUtil.fail(401,"请选择渠道商");
        }
        return ResponseUtil.ok(amountFreezeDubboService.listPartnerFreezeAmountDetail(reqVO, pageNum, pageSize));
    }


    @GetMapping("/searchFreezeAmountDetailDealer")
    @ApiOperation(value = "店端查询渠道商资金冻结变动明细")
    public ApiResult amountFreezeChangeDetailDealer(PartnerFreezeAmountReqVO reqVO,Integer pageNum, Integer pageSize,@CurrentUser LoginInfo user) throws Exception {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO == null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是渠道用户，请使用渠道用户登录！");
        }
        reqVO.setPartnerCode(user.getPartnerCode());
        return ResponseUtil.ok(amountFreezeDubboService.listPartnerFreezeAmountDetail(reqVO, pageNum, pageSize));
    }


}
